<style lang="less">
  .f-el-sy{
    /*text-align: center;*/
    /*line-height: 45px;*/
    border: 1px solid #c8c8c8;
    margin-right: 10px;
    display: inline-block;
    min-width: 150px;
    margin-bottom: 5px;
    height: 25px;

  }
  .f-w100{
    width: 100%;
  }
</style>
<template>
  <div>
    <search-bar more-display>
      <el-form ref="searchForm" :model="searchForm" label-position="right" class="f-bg"
               label-width="120px">
        <el-row :span="24">
          <el-col :span="8">
            <el-form-item label="预约优惠名称" prop="LIKE_freightAppointName">
              <el-input v-model="searchForm.LIKE_freightAppointName" class="f-w70" placeholder="请输入预约优惠名称"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item  label="发布渠道" prop="EQ_stowageId">
              <el-select v-model="searchForm.EQ_stowageId"
                         class="f-w70"
                         filterable
                         remote
                         :remote-method="getStowagesCores"
                         placeholder="请选择发布渠道">
                <el-option v-for="stowagesCore in stowagesCores"
                           :label="stowagesCore.name"
                           :key="stowagesCore.id"
                           :value="stowagesCore.id"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <div class="grid-content bg-purple">
              <el-form-item class="f-bg" label="启用状态" prop="EQ_status">
                <el-select v-model="searchForm.EQ_status" class="f-w70"
                           @visible-change="searchFaStatus"
                           filterable placeholder="请选启用状态">
                  <el-option style="width: 200px" v-for="(fs,index) in faStatus"
                             :label="fs.cnDictValname"
                             :value="fs.dictVal" :key="index"></el-option>
                </el-select>
              </el-form-item>
            </div>
          </el-col>
        </el-row>
      </el-form>
    </search-bar>
    <div class="f-mt f-wa f-fl" style="margin-bottom: 10px">
      <el-button type="primary" class="f-wa f-mr20"   @click="openSaveFreightAppoint">新增</el-button>
    </div>

    <div class="f-mt f-wa">
      <el-button type="primary" class="f-wa f-fr f-ml10 f-mr20" @click="reset()">重置</el-button>
      <el-button type="primary" class="f-wa f-fr f-ml10 "  @click="findFreightAppoints">查询</el-button>
    </div>

    <el-table :data="tableData" border tooltip-effect="dark" style="width: 100% ;margin-top: 10px">
      <el-table-column type="index" label="序号" width="100"></el-table-column>
      <el-table-column prop="freightAppointName"
                       label="预约下单优惠名称"
                       width="230">
      </el-table-column>
      <el-table-column prop="createDate"
                       label="创建日期"
                       width="230">
      </el-table-column>
      <el-table-column prop="createUserName"
                       label="创建人"
                       width="230">
      </el-table-column>
      <el-table-column prop="stowageName"
                       label="发布渠道"
                       width="230">
      </el-table-column>
      <el-table-column prop="statusName"
                       label="启用状态"
                       width="230">
      </el-table-column>
      <el-table-column label="操作" width="380">
        <template slot-scope="scope">
          <el-button   type="success" v-if="scope.row.status !== 111002001" @click="controlFreightAppointStatus(scope.row.id,111002001,'启用')">启用</el-button>
          <el-button   type="warning" v-if="scope.row.status === 111002001" @click="controlFreightAppointStatus(scope.row.id,111002002,'禁用')">禁用</el-button>
          <el-button   type="primary" v-if="scope.row.status !== 111002001" @click="openFreightAppointDetail(scope.row.id,true)">维护明细</el-button>
          <el-button   type="primary" v-if="scope.row.status === 111002001" @click="openFreightAppointDetail(scope.row.id,false)">明细</el-button>
          <el-button   type="primary" v-if="scope.row.status !== 111002001" @click="openUpdateFreightAppoint(scope.row)">编辑</el-button>
          <el-button   type="danger" v-if="scope.row.status !== 111002001" @click="doFreightAppointDelete(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination class="f-mt10"
                   :current-page="currentPage"
                   :page-size="pageSize"
                   @size-change="handleSizeChange"
                   @current-change="handleCurrentChange"
                   layout="total,sizes,prev, pager, next, jumper"
                   :total="total" style="float: right">
    </el-pagination>

    <!--打开辐射 弹窗 -->
    <el-dialog :title="radiateTitle"  :visible.sync="radiateCityVisible" :close-on-click-modal="false">
      <el-table :data="radiateCityTableData" highlight-current-row border
                v-loading="listLoading3" style="width: 100%;">
        <el-table-column type="index" label="序号" width="100" >
        </el-table-column>
        <el-table-column label="管辖范围(区/县)">
          <template slot-scope="scope">
            {{scope.row.province}}   {{scope.row.city}}   {{scope.row.county}}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="100">
          <template slot-scope="scope">
            <el-button  type="primary" @click="getEditBYId1(scope.$index, scope.row)">选择
            </el-button>
          </template>
        </el-table-column>

      </el-table>

      <!--工具条-->
      <el-col :span="24" class="toolbar">
        <el-pagination
          :current-page="currentPage3"
          :page-size="pageSize3"
          layout="total,sizes,prev, pager, next, jumper"
          :total="total3" style="float: right">
        </el-pagination>
      </el-col>

      <div slot="footer" class="dialog-footer">
        <el-button @click="cancelRadiateCity">取消</el-button>
      </div>

    </el-dialog>

    <!--优惠线路主信息新增&&编辑Dialog-->
    <el-dialog :title="faSaveOrModifyTitle" :visible.sync="faSaveOrModifyDialog" size="tiny">
      <el-form ref="faSaveOrModifyForm" :model="faSaveOrModifyForm" label-width="110px">
        <el-form-item label="预约优惠名称" prop="freightAppointName" :rules="[{required: true, type:'string', message: '请输入预约优惠名称', trigger: 'blur'}]">
          <el-input class="f-w70" v-model="faSaveOrModifyForm.freightAppointName"></el-input>
        </el-form-item>
        <el-form-item class="f-mb10" label="发布渠道" prop="stowageId" :rules="[{required: true, type:'string', message: '请选择发布渠道', trigger: 'blur'}]">
          <el-select v-model="faSaveOrModifyForm.stowageId"
                     class="f-w70"
                     filterable
                     remote
                     :remote-method="getStowagesCores"
                     placeholder="请选择发布渠道">
            <el-option v-for="stowagesCore in stowagesCores"
                       :label="stowagesCore.name"
                       :key="stowagesCore.id"
                       :value="stowagesCore.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="备注信息">
          <el-input class="f-w70" type="textarea" v-model="faSaveOrModifyForm.remark"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="faSaveOrModifyDialog = false">取消</el-button>
          <el-button type="primary" @click="saveFindFreightAppoint" :loading="submitLoading">确认</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

    <!--优惠线路 明细 信息新增&&编辑Dialog-->
    <el-dialog :title="fadSaveOrModifyTitle" :visible.sync="fadSaveOrModifyDialog" size="tiny">
      <el-form ref="fadSaveOrModifyForm" :model="fadSaveOrModifyForm" label-width="110px">
        <el-form-item label="始发地" prop="orgAddressAll">
          <el-input :disabled="true" v-model="fadSaveOrModifyForm.orgAddressAll" style="width: 70%"></el-input>
          <el-button  type="primary" @click="radiateCityBYId()">添加
          </el-button>
        </el-form-item>
        <el-form-item label="目的地" prop="addrsssArry">
          <address-select v-model="fadSaveOrModifyForm.addrsssArry"
                          placeholder="请选择地址" >
          </address-select>
        </el-form-item>
        <el-form-item label="备注信息">
          <el-input class="f-w70" type="textarea" v-model="fadSaveOrModifyForm.remark"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="saveFindFreightAppointDetail" :loading="submitLoading">提交</el-button>
          <el-button @click="fadSaveOrModifyDialog = false">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

    <!--优惠线路 折扣 信息新增&&编辑Dialog-->
    <el-dialog :title="farSaveOrModifyTitle" :visible.sync="farSaveOrModifyDialog" size="tiny">
      <el-form ref="farSaveOrModifyForm" :model="farSaveOrModifyForm" label-width="110px">
        <el-form-item label="预约下单天数" prop="appointDay" :rules="[{required: true, type:'number', message: '请输入预约下单天数', trigger: 'blur'},{validator:this.appointDayFun,trigger: 'blur'}]">
          <el-input class="f-w70" v-model.number="farSaveOrModifyForm.appointDay"></el-input>
        </el-form-item>
        <el-form-item label="优惠比例" prop="discountRate" :rules="[{required: true, type:'number', message: '请输入优惠比例', trigger: 'blur', min:0, max:1}]">
          <el-input class="f-w70" v-model.number="farSaveOrModifyForm.discountRate"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="saveFreightAppointRoute" :loading="submitLoading">提交</el-button>
          <el-button @click="farSaveOrModifyDialog = false">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

    <!--预约下单优惠明细Dialog-->
    <el-dialog title="预约下单优惠明细" :visible.sync="faDetailDialog" size="large">
      <el-row :gutter="20">
        <el-col :span="8">
          <div class="grid-content">
            预约优惠名称: <label class="f-el-sy" v-html="this.faSaveOrModifyForm.freightAppointName"></label>
          </div>
        </el-col>
        <el-col :span="8">
          <div class="grid-content">
            发布渠道: <label class="f-el-sy" v-html="this.faSaveOrModifyForm.stowageName"></label>
          </div>
        </el-col>
        <el-col :span="8">
          <div class="grid-content">
            创建日期: <label class="f-el-sy" v-html="this.faSaveOrModifyForm.createDate"></label>
          </div>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="16">
          <div class="grid-content">
            备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注: <label class="f-el-sy" v-html="this.faSaveOrModifyForm.remark"></label>
          </div>
        </el-col>
        <el-col :span="8"><div class="grid-content"></div></el-col>
      </el-row>
      <div style="display: flex;justify-content: center">
        <div style="width: 60%">
          <div class="toolbar" style="width: 100%">
            <el-form ref="searchDetailForm" :model="searchDetailForm" label-position="right" label-width="60px" style="padding-top: 15px;margin-bottom: 5px">
              <el-row>
                <el-col :span="8">
                  <div class="grid-content">
                    <el-form-item label="始发地" prop="LIKE_orgAddressAll">
                      <el-input v-model="searchDetailForm.LIKE_orgAddressAll" class="f-w100" placeholder="请输入始发地"></el-input>
                    </el-form-item>
                  </div>
                </el-col>
                <el-col :span="8">
                  <div class="grid-content">
                    <el-form-item label="目的地" prop="LIKE_desAddressAll">
                      <el-input v-model="searchDetailForm.LIKE_desAddressAll" class="f-w100" placeholder="请输入目的地"></el-input>
                    </el-form-item>
                  </div>
                </el-col>
                <!--<el-col :span="8">-->
                  <!--<div class="grid-content bg-purple">-->
                  <!--<el-form-item-->
                  <!--prop="ageingType" label="运输方式">-->
                  <!--<el-select-->
                  <!--multiple-->
                  <!--v-model="searchDetailForm.LIKE_ageingType">-->
                  <!--<el-option v-for="item in $store.getters.AGING_CLASSIFICATION"-->
                  <!--:disabled="[112006003,112006004].indexOf(item.dictVal)> -1"-->
                  <!--:key="item.id" :label="item.cnDictValname" :value="item.dictVal"></el-option>-->
                  <!--</el-select>-->
                  <!--</el-form-item>-->
                  <!--</div>-->
                <!--</el-col>-->
              </el-row>
            </el-form>
          </div>
          <div class="f-mt f-wa f-fl" style="margin-bottom: 10px">
            <el-button type="primary" v-if="lookOrModifyDetail" class="f-wa f-mr20" @click="openSaveFreightAppointDetail">新增线路</el-button>
            <el-button type="primary" v-if="lookOrModifyDetail" @click="exportFreightAppoint">导出</el-button>
            <el-upload
              class="upload-demo"
              v-if="lookOrModifyDetail"
              style="display: inline-block"
              :file-list="fileList"
              :on-success="handleOnUploadSuccess"
              :action="'/api/v2.0/admin/freight/appoint/'+ this.selectRowId +'/upload' ">
              <el-button  type="primary">导入</el-button>
            </el-upload>
          </div>

          <div class="f-mt f-wa">
            <el-button type="primary" class="f-wa f-fr f-ml10 f-mr20" @click="resetDetail">重置</el-button>
            <el-button type="primary" class="f-wa f-fr f-ml10 "  @click="findFreightAppointDetail">查询</el-button>
          </div>

          <el-table :data="tableDetailData" border tooltip-effect="dark" style="width: 100% ;margin-top: 10px" @row-click="selectBaseDetail">
            <el-table-column type="index" label="序号" width="50"></el-table-column>
            <el-table-column prop="orgAddressAll" show-overflow-tooltip label="始发地" width="120">
            </el-table-column>
            <el-table-column prop="desAddressAll" show-overflow-tooltip label="目的地" width="150">
            </el-table-column>
            <!--<el-table-column prop="ageingTypeName"-->
            <!--label="运输方式"-->
            <!--width="200">-->
            <!--</el-table-column>-->
            <el-table-column prop="remark" v label="备注" width="80">
            </el-table-column>
            <el-table-column prop="status" label="状态" width="50">
              <template slot-scope="scope">
                <label v-if="scope.row.status===111002001">启用</label>
                <label v-if="scope.row.status===111002002">禁用</label>
              </template>
            </el-table-column>
            <el-table-column fixed="right" label="操作" width="220">
              <template slot-scope="scope">
                <el-button   type="primary" v-if="lookOrModifyDetail && scope.row.status !== 111002001" @click="controlFaDetailStatus(scope.row.id,111002001,'启用')" style="margin-left: 5px">启用</el-button>
                <el-button   type="warning" v-if="lookOrModifyDetail && scope.row.status === 111002001" @click="controlFaDetailStatus(scope.row.id,111002002,'禁用')" style="margin-left: 5px">禁用</el-button>
                <el-button   type="primary" v-if="lookOrModifyDetail && scope.row.status !== 111002001" @click="openUpdateFreightAppointDetail(scope.row)" style="margin-left: 5px">编辑</el-button>
                <el-button   type="danger" v-if="lookOrModifyDetail && scope.row.status !== 111002001" @click="doFreightAppointDiscountDelete(scope.row.id)" style="margin-left: 5px">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
          <el-row>
            <el-pagination class="f-mt10"
                           :current-page="detailCurrentPage"
                           :page-size="detailPageSize"
                           @size-change="detailHandleSizeChange"
                           @current-change="detailHandleCurrentChange"
                           layout="total,sizes,prev, pager, next, jumper"
                           :total="detailTotal">
            </el-pagination>
          </el-row>

        </div>
        <div  style="width: 40%;margin-left: 10px">
          <div class="f-mt f-wa f-fl" style="margin-bottom: 10px">
            <el-button type="primary" class="f-wa f-mr20" v-if="lookOrModifyDetail" @click="openSaveFreightAppointRoute">新增</el-button>
          </div>
          <el-table :data="tableRouteData" border tooltip-effect="dark" style="width: 100% ;margin-top: 10px">
            <el-table-column type="index" label="序号" width="80"></el-table-column>
            <el-table-column prop="appointDay"
                             label="预约下单天数"
                             width="150">
            </el-table-column>
            <el-table-column prop="discountRate"
                             label="优惠比例"
                             width="150">
            </el-table-column>
            <el-table-column label="操作" width="150">
              <template slot-scope="scope">
                <el-button   type="primary" v-if="lookOrModifyDetail && scope.row.status !== 111002001" @click="openUpdateFreightAppointRoute(scope.row)">编辑</el-button>
                <el-button   type="primary" v-if="lookOrModifyDetail && scope.row.status !== 111002001" @click="doFreightAppointRouteDelete(scope.row.id)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import {
  getByStowageCore
} from '../../api/system/RadiateCity';
import {searchFreightAppointRoute, searchFreightAppointDetail, delFreightAppoint, getFreightAppointRoute, delFreightAppointRoute, saveOrUpdateFreightAppointRoute, getFreightAppoint, delFreightAppointDiscount, saveOrUpdateFreightAppointDiscount, searchFreightAppoints, saveOrUpdateFreightAppoint, updateFreightAppointStatus, searchFreightAppointDiscounts, updateFaDetailStatus} from '../../api/freight/freightAppoint.js';
import {searchStowageCore} from '../../api/system/stowageCore';
import {isEmpty, objToFilter, getSelectObect, resetObjNull} from '../../lib/util.js';
import {getDictEntityByDictCode} from '../../api/system/Dict.js';
export default {
  data () {
    return {
      lookOrModifyDetail: true,
      listLoading3: false,
      radiateCityVisible: false,
      radiateTitle: '辐射城市',
      radiateCityTableData: [],
      selectRowId: '',
      selectRowDetail: {},
      submitLoading: false,
      stowagesCores: [],
      faStatus: [],
      faSaveOrModifyTitle: '',
      fadSaveOrModifyTitle: '',
      farSaveOrModifyTitle: '',
      faSaveOrModifyDialog: false,
      fadSaveOrModifyDialog: false,
      farSaveOrModifyDialog: false,
      faDetailDialog: false,
      faSaveOrModifyForm: {
        id: '',
        freightAppointName: '',
        stowageId: '',
        stowageName: '',
        status: '',
        statusName: '',
        remark: '',
        createDate: ''
      },
      fadSaveOrModifyForm: {
        id: '',
        freightAppoint: {},
        originatingCity: '',
        destinationCity: '',
        orgAddressAll: '',
        desAddressAll: '',
        status: '',
        statusName: '',
        remark: '',
        ageingType: '',
        ageingTypeName: '',
        addrsssArry: []
      },
      farSaveOrModifyForm: {
        id: '',
        freightAppointDiscount: {},
        appointDay: '',
        discountRate: ''
      },
      total: 0,
      detailTotal: 0,
      total3: 0,
      currentPage: 1,
      detailCurrentPage: 1,
      currentPage3: 1,
      pageSize: 10,
      detailPageSize: 10,
      pageSize3: 10,
      tableData: [],
      tableDetailData: [],
      tableRouteData: [],
      searchDetailForm: {
        LIKE_orgAddressAll: '',
        LIKE_desAddressAll: '',
        LIKE_ageingType: ''
      },
      searchForm: {
        LIKE_freightAppointName: '',
        EQ_stowageId: '',
        EQ_status: ''
      },
      param: {
        filters: '',
        sorts: '',
        size: 15,
        page: 1
      },
      detailParam: {
        filters: '',
        sorts: '',
        size: 15,
        page: 1
      },
      routeParam: {
        filters: '',
        sorts: '',
        size: 10000,
        page: 1
      },
      fileList: []
    };
  },
  methods: {
    appointDayFun (rule, value, callback) {
      if (Math.floor(value) !== value) {
        return callback(new Error('预定优惠天数只能输入整数'));
      }
      if (value < 1) {
        return callback(new Error('预定优惠天数只能输入正整数'));
      }
      let fap = this.selectRowDetail.freightAppointRoutes;
      for (let i = 0; i < fap.length; i++) {
        if (this.farSaveOrModifyForm !== null && this.farSaveOrModifyForm.id === fap[i].id && this.farSaveOrModifyForm.appointDay === value) {
          continue;
        }
        if (fap[i].appointDay === value) {
          return callback(new Error('不允许维护重复天数,' + value + '已存在'));
        }
      }
      return callback();
    },
    handleOnUploadSuccess (response) {
      this.fileList = [];
      if (response.successFlg) {
        this.findFreightAppointDetail();
        this.$message('导入成功');
      } else {
        this.$message.error(response.errorMsg);
      }
    },
    exportFreightAppoint () {
      location.href = '/api/v2.0/admin/freight_appoint_details/' + this.selectRowId + '/download';
    },
    selectBaseDetail (row) {
      this.selectRowDetail = row;
      this.routeParam.filters = 'EQ_freightAppointDiscount.id=' + row.id + ';';
      this.routeParam.sorts = '+createDate';
      searchFreightAppointRoute(this.routeParam).then((res) => {
        if (res.data.successFlg === true) {
          this.tableRouteData = res.data.detailModelList;
        }
      }).catch(function (error) {
        this.$message.error('查询失败:' + error);
      });
    },
    // 辐射城市选择数据操作
    getEditBYId1 (index, row) {
      this.$confirm('确认选择该始发城市吗?', '提示', {
        type: 'warning'
      }).then(() => {
        if (!isEmpty(row.provinceId) && !isEmpty(row.cityId) && !isEmpty(row.countyId)) {
          this.fadSaveOrModifyForm.originatingCity = row.provinceId + ',' + row.cityId + ',' + row.countyId + ',';
        }
        if (!isEmpty(row.provinceId) && !isEmpty(row.cityId)) {
          this.fadSaveOrModifyForm.originatingCity = row.provinceId + ',' + row.cityId + ',';
        }
        if (!isEmpty(row.province) && !isEmpty(row.city) && !isEmpty(row.county)) {
          this.fadSaveOrModifyForm.orgAddressAll = row.province + '-' + row.city + '-' + row.county;
        }
        if (!isEmpty(row.province) && !isEmpty(row.city)) {
          this.fadSaveOrModifyForm.orgAddressAll = row.province + '-' + row.city;
        }
        this.radiateCityVisible = false;
      }).catch(() => {
      });
    },
    // 取消选择辐射城市
    cancelRadiateCity () {
      this.fadSaveOrModifyForm.originatingCity = '';
      this.fadSaveOrModifyForm.orgAddressAll = '';
      this.radiateCityVisible = false;
    },
    // 打开辐射城市窗口
    radiateCityBYId () {
      getByStowageCore({
        page: this.currentPage3,
        size: this.pageSize3,
        filters: '',
        id: this.faSaveOrModifyForm.stowageId,
        sorts: ''
      }).then((res) => {
        this.radiateCityVisible = true;
        this.radiateCityTableData = res.data.detailModelList;
        this.currentPage3 = res.data.currPage;
        this.total3 = res.data.totalCount;
        this.pageSize3 = res.data.pageSize;
        this.listLoading3 = false;
      });
    },
    reset () {
      this.tableData = [];
      resetObjNull(this.searchForm);
    },
    resetDetail () {
      this.tableDetailData = [];
      resetObjNull(this.searchDetailForm);
    },
    controlFreightAppointStatus (id, status, btnName) {
      this.$confirm('确认 ' + btnName + ' 吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        updateFreightAppointStatus({
          id: id,
          status: status
        }).then((res) => {
          if (res.data.successFlg === true) {
            this.init();
          } else {
            this.$message.error(res.data.errorMsg);
          }
        }).catch(function (error) {
          console.log(error);
        }).catch(function (error) {
          this.$message.error(btnName + '失败');
          console.log(error);
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消' + btnName
        });
      });
    },
    controlFaDetailStatus (id, status, btnName) {
      this.$confirm('确认 ' + btnName + ' 吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        updateFaDetailStatus({
          id: id,
          status: status
        }).then((res) => {
          if (res.data.successFlg === true) {
            this.openFreightAppointDetail(this.selectRowId, this.lookOrModifyDetail);
          } else {
            this.$message.error(res.data.errorMsg);
          }
        }).catch(function (error) {
          console.log(error);
        }).catch(function (error) {
          this.$message.error(btnName + '失败');
          console.log(error);
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消' + btnName
        });
      });
    },
    searchFaStatus () {
      getDictEntityByDictCode({token: this.token, dictCode: 111002}).then((res) => {
        this.faStatus = res.data.detailModelList;
      });
    },
    saveFindFreightAppoint () {
      // 表单验证
      this.$refs['faSaveOrModifyForm'].validate((valid) => {
        if (valid) {
          this.submitLoading = true;
          this.faSaveOrModifyForm.stowageName = getSelectObect(this.faSaveOrModifyForm.stowageId, 'id', this.stowagesCores).name;
          saveOrUpdateFreightAppoint(this.faSaveOrModifyForm).then((res) => {
            this.submitLoading = false;
            if (res.data.successFlg === true) {
              this.faSaveOrModifyDialog = false;
              this.init();
            } else {
              this.$message.error(res.data.errorMsg);
            }
          }).catch(function (error) {
            console.log(error);
          });
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    doFreightAppointDiscountDelete (id) {
      this.$confirm('确认 删除 吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        delFreightAppointDiscount(id).then((res) => {
          this.submitLoading = false;
          if (res.data.successFlg === true) {
            this.faSaveOrModifyDialog = false;
            this.openFreightAppointDetail(this.selectRowId, this.lookOrModifyDetail);
          } else {
            this.$message.error(res.data.errorMsg);
          }
        }).catch(function (error) {
          console.log(error);
        }).catch(function (error) {
          this.$message.error('删除失败');
          console.log(error);
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        });
      });
    },
    doFreightAppointRouteDelete (id) {
      this.$confirm('确认 删除 吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        delFreightAppointRoute(id).then((res) => {
          this.submitLoading = false;
          if (res.data.successFlg === true) {
            this.faSaveOrModifyDialog = false;
            this.routeParam.filters = 'EQ_freightAppointDiscount.id=' + this.selectRowDetail.id + ';';
            this.routeParam.sorts = '+createDate';
            searchFreightAppointRoute(this.routeParam).then((res) => {
              if (res.data.successFlg === true) {
                this.tableRouteData = res.data.detailModelList;
              }
            }).catch(function (error) {
              this.$message.error('查询失败:' + error);
            });
          } else {
            this.$message.error(res.data.errorMsg);
          }
        }).catch(function (error) {
          console.log(error);
        }).catch(function (error) {
          this.$message.error('删除失败');
          console.log(error);
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        });
      });
    },
    doFreightAppointDelete (id) {
      this.$confirm('确认 删除 吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        delFreightAppoint(id).then((res) => {
          this.submitLoading = false;
          if (res.data.successFlg === true) {
            this.findFreightAppoints();
          } else {
            this.$message.error(res.data.errorMsg);
          }
        }).catch(function (error) {
          console.log(error);
        }).catch(function (error) {
          this.$message.error('删除失败');
          console.log(error);
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        });
      });
    },
    saveFindFreightAppointDetail () {
      // 表单验证
      this.$refs['fadSaveOrModifyForm'].validate((valid) => {
        if (valid) {
          this.submitLoading = true;
          this.fadSaveOrModifyForm.destinationCity = this.fadSaveOrModifyForm.addrsssArry.join(',') + ',';
          this.fadSaveOrModifyForm.freightAppoint = this.faSaveOrModifyForm;
          saveOrUpdateFreightAppointDiscount(this.fadSaveOrModifyForm).then((res) => {
            this.submitLoading = false;
            if (res.data.successFlg === true) {
              this.openFreightAppointDetail(this.selectRowId, this.lookOrModifyDetail);
            } else {
              this.$message.error(res.data.errorMsg);
            }
            this.fadSaveOrModifyDialog = false;
          }).catch(function (error) {
            console.log(error);
          });
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    saveFreightAppointRoute () {
      // 表单验证
      this.$refs['farSaveOrModifyForm'].validate((valid) => {
        if (valid) {
          this.submitLoading = true;
          this.farSaveOrModifyForm.freightAppointDiscount = this.selectRowDetail;
          saveOrUpdateFreightAppointRoute(this.farSaveOrModifyForm).then((res) => {
            this.submitLoading = false;
            if (res.data.successFlg) {
              this.farSaveOrModifyDialog = false;
              this.routeParam.filters = 'EQ_freightAppointDiscount.id=' + this.selectRowDetail.id + ';';
              this.routeParam.sorts = '+createDate';
              searchFreightAppointRoute(this.routeParam).then((res) => {
                if (res.data.successFlg === true) {
                  this.tableRouteData = res.data.detailModelList;
                }
              }).catch(function (error) {
                this.$message.error('查询失败:' + error);
              });
            } else {
              this.$message.error(res.data.errorMsg);
            }
          }).catch(function (error) {
            console.log(error);
          });
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    openFreightAppointDetail (id, flag) {
      this.tableRouteData = [];
      this.lookOrModifyDetail = flag;
      resetObjNull(this.fadSaveOrModifyForm);
      this.selectRowId = id;
      let o = Object.assign({}, this.searchDetailForm);
      let filters = objToFilter(o);
      filters += filters + 'EQ_freightAppoint.id=' + id + ';';
      this.searchFreightAppointDiscountsTable(filters);
      getFreightAppoint(id).then((res) => {
        if (res.data.successFlg === true) {
          this.faSaveOrModifyForm = res.data.obj;
        }
      }).catch(function (error) {
        this.$message.error('查询失败:' + error);
      });
      this.faDetailDialog = true;
    },
    openSaveFreightAppointRoute () {
      if (isEmpty(this.selectRowDetail.id)) {
        return this.$message.error('请选择一条优惠线路');
      }
      resetObjNull(this.farSaveOrModifyForm);
      this.farSaveOrModifyDialog = true;
      this.farSaveOrModifyTitle = '新增';
    },
    openSaveFreightAppointDetail () {
      resetObjNull(this.fadSaveOrModifyForm);
      this.fadSaveOrModifyDialog = true;
      this.fadSaveOrModifyTitle = '新增';
    },
    openSaveFreightAppoint () {
      resetObjNull(this.faSaveOrModifyForm);
      this.faSaveOrModifyDialog = true;
      this.faSaveOrModifyTitle = '新增预约下单优惠';
    },
    openUpdateFreightAppointRoute (row) {
      resetObjNull(this.farSaveOrModifyForm);
      getFreightAppointRoute(row.id).then((res) => {
        if (res.data.successFlg === true) {
          this.farSaveOrModifyForm = res.data.obj;
        }
      }).catch(function (error) {
        this.$message.error('查询失败:' + error);
      });
      this.farSaveOrModifyDialog = true;
      this.farSaveOrModifyTitle = '编辑预约下单优惠折扣';
    },
    openUpdateFreightAppoint (row) {
      resetObjNull(this.faSaveOrModifyForm);
      getFreightAppoint(row.id).then((res) => {
        if (res.data.successFlg === true) {
          this.faSaveOrModifyForm = res.data.obj;
        }
      }).catch(function (error) {
        this.$message.error('查询失败:' + error);
      });
      this.faSaveOrModifyDialog = true;
      this.faSaveOrModifyTitle = '编辑预约下单优惠线路';
    },
    openUpdateFreightAppointDetail (row) {
      this.fadSaveOrModifyForm = row;
      this.fadSaveOrModifyForm.addrsssArry = row.destinationCity.substring(0, row.destinationCity.length - 1).split(',').map(function (ad) {
        return +ad;
      });
      this.fadSaveOrModifyDialog = true;
      this.fadSaveOrModifyTitle = '编辑预约下单优惠';
    },
    findFreightAppoints () {
      let o = Object.assign({}, this.searchForm);
      let filters = objToFilter(o);
      this.searchFreightAppointTable(filters);
    },
    findFreightAppointDetail () {
      let o = Object.assign({}, this.searchDetailForm);
      let filters = objToFilter(o);
      filters += ';EQ_freightAppoint.id=' + this.selectRowId + ';';
      this.searchFreightAppointDetailTable(filters);
    },
    searchFreightAppointDiscountsTable (filters) {
      this.detailParam.filters = filters;
      this.detailParam.sorts = '+createDate';
      this.detailParam.size = this.detailPageSize;
      this.detailParam.page = this.detailCurrentPage;
      searchFreightAppointDiscounts(this.detailParam).then((res) => {
        if (res.data.successFlg === true) {
          this.tableDetailData = res.data.detailModelList;
          this.detailCurrentPage = res.data.currPage;
          this.detailTotal = res.data.totalCount;
          this.detailPageSize = res.data.pageSize;
        }
      }).catch(function (error) {
        this.$message.error('查询失败:' + error);
      });
    },
    searchFreightAppointTable (filters) {
      this.param.filters = filters;
      this.param.sorts = '+createDate';
      this.param.size = this.pageSize;
      this.param.page = this.currentPage;
      searchFreightAppoints(this.param).then((res) => {
        if (res.data.successFlg === true) {
          this.tableData = res.data.detailModelList;
          this.currentPage = res.data.currPage;
          this.total = res.data.totalCount;
          this.pageSize = res.data.pageSize;
        }
      }).catch(function (error) {
        this.$message.error('查询失败:' + error);
      });
    },
    searchFreightAppointDetailTable (filters) {
      this.detailParam.filters = filters;
      this.detailParam.sorts = '+createDate';
      this.detailParam.size = this.detailPageSize;
      this.detailParam.page = this.detailCurrentPage;
      searchFreightAppointDetail(this.detailParam).then((res) => {
        if (res.data.successFlg === true) {
          this.tableDetailData = res.data.detailModelList;
          this.detailCurrentPage = res.data.currPage;
          this.detailTotal = res.data.totalCount;
          this.detailPageSize = res.data.pageSize;
        }
      }).catch(function (error) {
        this.$message.error('查询失败:' + error);
      });
    },
    // 每页几条操作
    detailHandleSizeChange (val) {
      this.pageSize = val;
      this.findFreightAppointDetail();
    },
    // 第几页操作
    detailHandleCurrentChange (val) {
      this.currentPage = val;
      this.findFreightAppointDetail();
    },
    // 每页几条操作
    handleSizeChange (val) {
      this.pageSize = val;
      this.findFreightAppoints();
    },
    // 第几页操作
    handleCurrentChange (val) {
      this.currentPage = val;
      this.findFreightAppoints();
    },
    getStowagesCores (val) {
      let filters = isEmpty(val) ? '' : 'LIKE_name=' + val;
      searchStowageCore({
        filters: filters,
        sorts: '',
        size: '15',
        page: '1'
      }).then((res) => {
        this.stowagesCores = res.data.detailModelList;
      });
    },
    init () {
      this.findFreightAppoints();
    }
  },
  // 初始化数据
  mounted () {
    this.init();
    this.$store.commit('initDict');
    this.getStowagesCores();
  }
};
</script>
